﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VISS.API.Users;

namespace VISS.Web.BackEnd.Modules.User {

    public partial class MessageListControl : System.Web.UI.UserControl {

        public List<UserMessageAdminEnt> MessageList { get; set; }

        public bool DisplayLink { get; set; }

        protected void Page_Load(object sender, EventArgs e) {
            if (MessageList != null && MessageList.Count > 0) {
                dtg_Message.DataSource = MessageList;
                dtg_Message.DataBind();
            }
        }
        protected void dtg_Message_RowDataBound(object sender, GridViewRowEventArgs e) {
            if (e.Row.RowIndex == -1)
                return;
            UserMessageAdminEnt item = (UserMessageAdminEnt)e.Row.DataItem;

            //Set Info
            string info = string.Empty;
            info = "<a href=\"xem_chi_tiet?key=" + item.SentUserKey + "\" target=\"_blank\">" + item.SenderName + "</a>";
            info += " đến ";
            info += "<a href=\"xem_chi_tiet?key=" + item.ReceivedUserKey + "\" target=\"_blank\">" + item.ReceiverName + "</a>";

            e.Row.Cells[0].Text = info;

            //Set Content
            string content = string.Empty;
            content = item.Content;
            if (DisplayLink) {
                content += "<br /><a href=\"tin_nhan?key=" + item.SentUserKey + "\">Xem tin nhắn từ " + item.SenderName + "</a>";
            }
            

            e.Row.Cells[1].Text = content;
        }
    }
}
